<template>
  <ele-modal
    :width="950"
    :visible="visible"
    :confirm-loading="loading"
    :title="'充值'"
    :body-style="{ paddingBottom: '8px' }"
    @update:visible="updateVisible"
    @ok="save"
  >
    <div class="margin-y-15 flex align-center" style="margin-left: 100px">
      <a-image width="40" height="40" />
      <div class="margin-left-15">
        <div>储值卡号：{{ props.editData.value_card_no || '' }}</div>
        <div class="flex align-center margin-top-15">
          <div
            >{{ props.editData.name || '' }}
            <span v-if="props.editData.nickname"
              >({{ props.editData.nickname || '' }})</span
            ></div
          >
          <span class="margin-left-24"
            >手机号：{{ props.editData.mobile || '' }}</span
          >
        </div>
      </div>
    </div>
    <a-form
      :label-col="{ md: { span: 5 }, sm: { span: 4 }, xs: { span: 24 } }"
      :wrapper-col="{ md: { span: 17 }, sm: { span: 20 }, xs: { span: 24 } }"
    >
      <a-row :gutter="24">
        <a-col :md="24" :sm="24" :xs="24">
          <a-form-item
            label="充值金额"
            :colon="false"
            v-bind="validateInfos.amount"
          >
            <a-input
              allow-clear
              placeholder="请输入"
              v-model:value="form.amount"
            />
          </a-form-item>
          <a-form-item label="赠送金额" :colon="false">
            <a-input
              allow-clear
              placeholder="请输入"
              v-model:value="form.send_amount"
            />
          </a-form-item>
          <a-form-item
            label="赠送卡劵"
            :colon="false"
            style="margin-bottom: 0px"
          >
            <a-row :gutter="24">
              <a-col :md="10" :sm="10" :xs="10">
                <a-form-item label="" :colon="false">
                  <a-select
                    allow-clear
                    placeholder="请选择"
                    optionFilterProp="label"
                    :options="[]"
                    v-model:value="form.send_coupon_id"
                  />
                </a-form-item>
              </a-col>
              <a-col :md="10" :sm="10" :xs="10">
                <a-form-item label="数量" :colon="false">
                  <a-input
                    allow-clear
                    placeholder="请输入"
                    v-model:value="form.coupon_num"
                  />
                </a-form-item>
              </a-col>
              <a-col :md="4" :sm="4" :xs="4">
                <a-form-item label="" :colon="false">
                  <span>张</span>
                </a-form-item>
              </a-col>
            </a-row>
          </a-form-item>
          <a-form-item
            label="赠送积分"
            :colon="false"
            style="margin-bottom: 0px"
          >
            <a-row :gutter="24">
              <a-col :md="10" :sm="10" :xs="10">
                <a-form-item label="" :colon="false">
                  <a-input
                    allow-clear
                    placeholder="请输入"
                    v-model:value="form.send_points"
                  />
                </a-form-item>
              </a-col>
              <a-col :md="10" :sm="10" :xs="10">
                <a-form-item label="有效期" :colon="false">
                  <a-input
                    allow-clear
                    placeholder="请输入"
                    v-model:value="form.points_valid"
                  />
                </a-form-item>
              </a-col>
              <a-col :md="4" :sm="4" :xs="4">
                <a-form-item label="" :colon="false">
                  <span>天</span>
                </a-form-item>
              </a-col>
            </a-row>
          </a-form-item>
          <a-form-item
            label="赠送礼金"
            :colon="false"
            style="margin-bottom: 0px"
          >
            <a-row :gutter="[24, 0]">
              <a-col :md="10" :sm="10" :xs="10">
                <a-form-item label="" :colon="false">
                  <a-input
                    allow-clear
                    placeholder="请输入"
                    v-model:value="form.send_cash"
                  />
                </a-form-item>
              </a-col>
              <a-col :md="10" :sm="10" :xs="10">
                <a-form-item label="有效期" :colon="false">
                  <a-input
                    allow-clear
                    placeholder="请输入"
                    v-model:value="form.cash_valid"
                  />
                </a-form-item>
              </a-col>
              <a-col :md="4" :sm="4" :xs="4">
                <a-form-item label="" :colon="false">
                  <span>天</span>
                </a-form-item>
              </a-col>
            </a-row>
          </a-form-item>
          <a-form-item
            label="销售人"
            :colon="false"
            v-bind="validateInfos.salesman_id"
          >
            <a-select
              allow-clear
              placeholder="请选择"
              optionFilterProp="label"
              :options="gouOptions"
              v-model:value="form.salesman_id"
            />
          </a-form-item>
          <a-form-item
            label="支付方式"
            :colon="false"
            v-bind="validateInfos.pay_type"
          >
            <a-select
              allow-clear
              placeholder="请选择"
              optionFilterProp="label"
              :options="payOptions"
              v-model:value="form.pay_type"
            />
          </a-form-item>
        </a-col>
      </a-row>
    </a-form>
  </ele-modal>
</template>

<script setup>
  import { ref, reactive, onMounted } from 'vue';
  import { Form, message } from 'ant-design-vue';

  import { salesman_list } from '@/api/order/order/jewelry_order';
  import { get_pay_type_select } from '@/api/setting/pay_type';
  // 表格列配置
  const useForm = Form.useForm;

  const emit = defineEmits(['done', 'update:visible']);

  const props = defineProps({
    // 弹窗是否打开
    visible: Boolean,
    editData: Object
  });

  // 提交状态
  const loading = ref(false);

  // 表单数据
  const form = reactive({
    member_id: props.editData.id,
    amount: '',
    send_amount: 0,
    send_coupon_id: null,
    coupon_num: '',
    send_points: '',
    points_valid: '',
    send_cash: '',
    cash_valid: '',
    salesman_id: null,
    pay_type: null
  });
  const gouOptions = ref([]);
  const payOptions = ref([]);

  onMounted(() => {
    console.log('props==', props);
    salesman_list().then((res) => {
      gouOptions.value = res.data;
    });
    get_pay_type_select().then((res) => {
      payOptions.value = res;
    });
  });

  // 表单验证规则
  const rules = reactive({
    amount: [
      {
        required: true,
        message: '请输入充值金额',
        type: 'string',
        trigger: 'change'
      }
    ],
    salesman_id: [
      {
        required: true,
        message: '请选择销售人',
        type: 'number',
        trigger: 'change'
      }
    ],
    pay_type: [
      {
        required: true,
        message: '请选择支付方式',
        type: 'string',
        trigger: 'change'
      }
    ]
  });

  const { validate, validateInfos } = useForm(form, rules);

  /* 保存*/
  const save = () => {
    validate()
      .then(() => {
        emit('done', form);
      })
      .catch(() => {});
  };
  /* 更新visible */
  const updateVisible = (value) => {
    emit('update:visible', value);
  };
</script>
<style scoped></style>
